package eip.chapter5.messagefilter.impl;

import java.io.StringReader;

import org.apache.axiom.om.OMElement;
import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.JiBXException;

import eip.chapter5.messagefilter.DeclarationMessage;

public abstract class DefaultDeclarationFacade {

	/**
	 * Uses JiBX to transform the incoming XML message to 
	 * a DeclarationMessage.
	 * 
	 * @param element the incoming element
	 * @return a declarationMessage.
	 * @throws JiBXException when a mapping error occurs
	 */
	protected DeclarationMessage transform(OMElement element) throws JiBXException {
		IBindingFactory bfact = BindingDirectory.getFactory(DeclarationMessage.class);
		return (DeclarationMessage) bfact.createUnmarshallingContext().
					unmarshalDocument(new StringReader(element.toString()),null);
	}
}
